package com.bolt.admin.module.log.dto.converter;

import com.bolt.admin.module.log.dto.LogDTO;
import com.bolt.admin.module.log.entity.LogEntity;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * Created by Administrator on 2018/11/27.
 */
public class LogConverter {
    private LogConverter() {
// do nothing
    }

    /**
     * Entity对象转换为DTO对象
     *
     * @param log DO对象
     * @return DTO对象
     */
    public static LogDTO toDTO(LogEntity log) {
        if (Objects.isNull(log)) {
            return null;
        }
        LogDTO result = new LogDTO();
        result.setId(log.getId());
        result.setModule(log.getModule());
        result.setMethod(log.getMethod());
        result.setParams(log.getParams());
        result.setDescription(log.getDescription());
        result.setRequestIp(log.getRequestIp());
        result.setTime(log.getTime());
        result.setUserId(log.getUserId());
        result.setUserName(log.getUserName());
        result.setAddress(log.getAddress());
        result.setBrowser(log.getBrowser());
        result.setExceptionDetail(log.getExceptionDetail());
        result.setCreateTime(log.getCreateTime());
        // TODO
        return result;
    }

    /**
     * DTO对象转换为Entity对象
     *
     * @param log DO对象
     * @return VO对象
     */
    public static LogEntity toEntity(LogDTO log) {
        if (Objects.isNull(log)) {
            return null;
        }
        LogEntity result = new LogEntity();
        result.setId(log.getId());
        result.setModule(log.getModule());
        result.setMethod(log.getMethod());
        result.setParams(log.getParams());
        result.setDescription(log.getDescription());
        result.setRequestIp(log.getRequestIp());
        result.setTime(log.getTime());
        result.setUserId(log.getUserId());
        result.setAddress(log.getAddress());
        result.setBrowser(log.getBrowser());
        result.setExceptionDetail(log.getExceptionDetail());
        result.setCreateTime(log.getCreateTime());
        // TODO
        return result;
    }

    /**
     * DTO对象转换为DO对象
     *
     * @param log DO对象
     * @return VO对象
     */
    public static LogEntity toEntity(LogEntity result, LogDTO log) {
        if (Objects.isNull(log)) {
            return null;
        }

        result.setModule(log.getModule());
        result.setMethod(log.getMethod());
        result.setParams(log.getParams());
        result.setDescription(log.getDescription());
        result.setRequestIp(log.getRequestIp());
        result.setTime(log.getTime());
        result.setUserId(log.getUserId());
        result.setAddress(log.getAddress());
        result.setBrowser(log.getBrowser());
        result.setExceptionDetail(log.getExceptionDetail());
        result.setCreateTime(log.getCreateTime());
// TODO
        return result;
    }

    /**
     * 批量 Entity对象转换为DTO对象
     *
     * @param logList Entity集合对象
     * @return DTO对象
     */
    public static List <LogDTO> toDTO(List <LogEntity> logList) {
        if (Objects.isNull(logList)) {
            return null;
        }
        return logList.stream().map(LogConverter::toDTO).collect(Collectors.toList());
    }



}
